package com.ruoyi.web.controller.employee;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee.domain.BaseRank;
import com.ruoyi.employee.service.IBaseRankService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职级管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/employee/rank")
public class BaseRankController extends BaseController
{
    @Autowired
    private IBaseRankService baseRankService;

    /**
     * 查询职级管理列表
     */
    @PreAuthorize("@ss.hasPermi('employee:rank:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseRank baseRank)
    {
        startPage();
        List<BaseRank> list = baseRankService.selectBaseRankList(baseRank);
        return getDataTable(list);
    }

    /**
     * 导出职级管理列表
     */
    @PreAuthorize("@ss.hasPermi('employee:rank:export')")
    @Log(title = "职级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseRank baseRank)
    {
        List<BaseRank> list = baseRankService.selectBaseRankList(baseRank);
        ExcelUtil<BaseRank> util = new ExcelUtil<BaseRank>(BaseRank.class);
        util.exportExcel(response, list, "职级管理数据");
    }

    /**
     * 获取职级管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:rank:query')")
    @GetMapping(value = "/{rankId}")
    public AjaxResult getInfo(@PathVariable("rankId") String rankId)
    {
        return success(baseRankService.selectBaseRankByRankId(rankId));
    }

    /**
     * 新增职级管理
     */
    @PreAuthorize("@ss.hasPermi('employee:rank:add')")
    @Log(title = "职级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseRank baseRank)
    {
        return toAjax(baseRankService.insertBaseRank(baseRank));
    }

    /**
     * 修改职级管理
     */
    @PreAuthorize("@ss.hasPermi('employee:rank:edit')")
    @Log(title = "职级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseRank baseRank)
    {
        return toAjax(baseRankService.updateBaseRank(baseRank));
    }

    /**
     * 删除职级管理
     */
    @PreAuthorize("@ss.hasPermi('employee:rank:remove')")
    @Log(title = "职级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rankIds}")
    public AjaxResult remove(@PathVariable String[] rankIds)
    {
        return toAjax(baseRankService.deleteBaseRankByRankIds(rankIds));
    }
}
